package com.example.shardingSphere.service;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.example.shardingSphere.base.AbstractService;
import com.example.shardingSphere.dao.OrderMapper;
import com.example.shardingSphere.entity.Order;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 订单service实现
 *
 * @time 2019年6月12日
 */
@Service
public class OrderServiceImpl extends AbstractService<OrderMapper, Order> {

    @Resource
    private OrderMapper orderMapper;

    public OrderMapper getBaseMapper() {
        return orderMapper;
    }

    /**
     * 新增
     *
     * @param order
     * @return
     * @time 2019年6月12日
     */
    public Map<String, Object> insert(@RequestBody(required = false) Order order) {

        Map<String, Object> result = new HashMap<>(16);
        if (this.save(order)) {
            result.put("status", 200);
            result.put("message", "新增成功！");
        }

        return result;
    }

    public Map<String, Object> insert1() {
        Order order = new Order();
        order.setPkId(System.currentTimeMillis());
        order.setOrderNo("NO" + System.currentTimeMillis());
        order.setOrderDetail("详情");
        order.setRemark("备注");
        order.setLogicDel("N");
//        order.setOrderStatus(1);
        Map<String, Object> result = new HashMap<>(16);
        if (this.save(order)) {
            result.put("status", 200);
            result.put("message", "新增成功！");
        }

        return result;
    }

    public Map<String, Object> getOrderList() {
        Map<String, Object> result = new HashMap<>(16);

        List<Order> orders = getBaseMapper().selectList(Wrappers.lambdaQuery());
        result.put("status", 200);
        result.put("message", "获取成功！");
        result.put("orders", orders);
        return result;
    }

}
